package com.ym.pms.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.stereotype.Component;

@Component
public class AlipayConfig {
    /**
     * 支付宝网关(https://openapi.alipay.com/gateway.do)
     * 沙盒网关(https://openapi.alipaydev.com/gateway.do)
     */
    public static String URL = "https://openapi.alipaydev.com/gateway.do";

    /**
     * 创建应用时产生的应用号
     */
    public static String APP_ID = "2021000116683083";

    /**
     * 开发者私钥
     */
    public static String APP_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCoWrdpF+HYzE++pwMQvimlH7P9fwvdX1IqXVG5Vm+SYf3LRuJziHH8gBGPOR35ev5tPBgMqdIIKP3S8vmLZKfzmsR1g66Sw67X/wBOEGPA+YaBAU9Owrom9id0yEy+jSrF9C9yJKJ3/GV/kWJI49hOCpGhqupz7QHnL4S+5pP750mZ5n51U1D6ofmRFfC5OzVSQjvDKAOJkaSOdiPVFURxDe+FcxGM8zuHVz0xOKdHHQuZNyiVjGqx2EDq7fWmURcpX1/UAQNlzVHAMLgVx/jVc0ViEhLYW3+Te/iakXHrTU2BaJxLGa1V5NgLkTfAzqlRMw2eRw+qzsPCAtaeTICzAgMBAAECggEAQJdNdwyqobsBfWwmSO4snCWlsMRlkPFZXNeg2zLGa6sc7Dit+RWIZg/crM6FKYp+wvojX/hnlKnleGGwTEK6DUR7y3pSKAzbsBMt0sWHACq76BLQkq8zLG+Ug8G1cAZJOtmMuoZDrzUu29qzkrOX8ZksdpJUkVWFPWWF0Jg2fpaGa9jKagQMu0ofKv44DOBE/I0UpXIqyn6uoc75kxwNbDcGF3+5gYduXYGuSpUK8omDgoyX19GXMuLdsgFYGEWBukW7byRuBK/t//2Db95DkjOxiVA6E9rGKWM6OgXRnp+NvM88w8RpPoWd07nSdRegW2myVqd4ZNEyjzoLRtSxAQKBgQDf/YdGdu5N0r4acWCvkBWsT4b3zvCAMEa6PJxbdZZOV2pMRS969utBdukCDRNYR+SONYNr5d3oDKwupOaMMislv2QjujVr0txBJ1Sk9G2t/nRQixY4pE2fuzJHAAOv1X6XiW9NW/mABDSAVZryWpee9pD1ar/gAsRA2n96snY4YwKBgQDAacyLIGAOe/WFedG7OVoiK64jwVJ4jMEro2hJiGiOksr0ePndb37QjjCybFvTCHXscnGTGfXfC9xTOMMiflqfEcaPNmLLM9P1oz/mCH4tWZGxWPYdxBdiNI66Lx6fQqzIad947qAA+t+z5kQTPJKJJF2y33PPgDIFdzob+TH/cQKBgQCxszhT3dy3Hv80iUg0YDHhjwI7rRA+Eo66B4XgRUxmgJFTSvwdKLGBMS4wM2Fqgza+35OQ0T+Ybh1Xr/k7tj1m6A0xDvR8wz977REJAOXWyO1MTNvnOepfU6rSix9hqxWQcTc8/z/UoQFp4wBXTynEskZUfUkWFfvOm8nQ9K43kwKBgQCdafDdIW90ahVDTZY4BYOn0PR2bAJ8fSrL+LOo9OAVRCKmPxKsBjtJhApy7hNxYsqW1kn0fpiYEav+qcF6xsR8vp4jK+tHMu+FVjlAiFIx58U5wf4X/ATlYvohd8sln/abP4KD/TUJmDTLiObIlhWL/SRq4kRszgQeVJxFpmkxAQKBgBxIkeY8aiAcZ/lV3QWGJlza4zazhRdDvGnKWS1cJW8hukWHU1I3mw+9OHsKiSw4ePFgB6itV0b6KJbukF0L9zDfilLI0ORyOAhjTkoYvKB9gAUZTtA+7x0dfFt9qoz8dA8ltQmPWrxqdoC3D6Ua2q3A3m5n+vq9uedmFCWwFmjr";

    /**
     * 参数返回格式, 只支持json
     */
    public static String FORMAT = "json";

    /**
     * 编码集,支持GBK/UTF-8,根据自己工程编码进行调整
     */
    public static String CHARSET = "UTF-8";

    /**
     * 支付宝公钥
     */
    public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqFq3aRfh2MxPvqcDEL4ppR+z/X8L3V9SKl1RuVZvkmH9y0bic4hx/IARjzkd+Xr+bTwYDKnSCCj90vL5i2Sn85rEdYOuksOu1/8AThBjwPmGgQFPTsK6JvYndMhMvo0qxfQvciSid/xlf5FiSOPYTgqRoarqc+0B5y+EvuaT++dJmeZ+dVNQ+qH5kRXwuTs1UkI7wygDiZGkjnYj1RVEcQ3vhXMRjPM7h1c9MTinRx0LmTcolYxqsdhA6u31plEXKV9f1AEDZc1RwDC4Fcf41XNFYhIS2Ft/k3v4mpFx601NgWicSxmtVeTYC5E3wM6pUTMNnkcPqs7DwgLWnkyAswIDAQAB";

    /**
     * 签名算法类型
     */
    public static String SIGN_TYPE = "RSA2";

    /**
     * 回调地址
     */
    public static String RETURN_URL = "http://localhost:8080/CallBack/alipay_back";

    /**
     * 异步通知地址
     */
    public static String NOTIFY_URL;

    /**
     * 私有化构造方法
     */
    private AlipayConfig(){}

    private volatile static AlipayClient instance = null;

    /**
     * 双重校验锁,单例模式
     * @return 支付宝请求客户端实例
     */
    public static AlipayClient getInstance(){
        if(instance == null){
            synchronized (AlipayConfig.class){
                if(instance == null){
                    instance = new DefaultAlipayClient(URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
                }
            }
        }
        return instance;
    }
}
